﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    class FileUtils
    {

        public static String LOGFILENAME = "D:/DCLOG-系统日志-";
        public static String DATALOGNAME = "d:/DATA-数据日志-";

        //读文件
        public static String[] readFile(String fileName){
            String[] datas = null;
            try
            {
                datas = File.ReadAllLines(fileName, Encoding.Default);
            }
            catch (Exception excep) {
                
            }
           
            return datas;
        }

        //写文件
        public static void writeFile(String[] text, String fileName) {
            try {
                File.WriteAllLines(fileName, text);
             }catch(Exception excep) {
                        
            }
           
        }

        //写日志
        public static void writeLogFile(String text) {
           DateTime date = DateTime.Now;
           String d =  date.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo);
           String name = date.ToString("yyyy-MM-dd-HH", DateTimeFormatInfo.InvariantInfo);
           File.AppendAllText(LOGFILENAME+name+".txt", d +"|"+ text + "\r\n");
        //  File.AppendAllText(LOGFILENAME,"\n");
        }

        //写数据日志
        public static void writeDataLogFile(String text) {
            DateTime date = DateTime.Now;
            String d = date.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo);
            String name = date.ToString("yyyy-MM-dd-HH", DateTimeFormatInfo.InvariantInfo);
            File.AppendAllText(DATALOGNAME + name + ".txt", d + "," + text + "\r\n");
        }
      
    }
}
